package com.yunji.cabinet.service.impl;

import com.yunji.cabinet.context.convert.UpgradeFileConvert;
import com.yunji.base.vo.UpgradeFileVO;
import com.yunji.cabinet.dao.IUpgradeFileDao;
import com.yunji.cabinet.domain.UpgradeFileDO;
import com.yunji.cabinet.params.CabinetVersionParam;
import com.yunji.cabinet.service.IUpgradeFileService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.cabinet.service.impl
 * @Title: CabinetVersionServiceImpl
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-07-01 14:06:08      V1.0        HuaAo       新建类
 */
@Service
public class UpgradeFileServiceImpl implements IUpgradeFileService {
    @Resource
    IUpgradeFileDao upgradeFileDao;

    @Override
    public boolean create(UpgradeFileDO version) {
        return upgradeFileDao.save(version);
    }

    @Override
    public List<UpgradeFileVO> searchVO(CabinetVersionParam param) {
        return UpgradeFileConvert.domainTOVOList(upgradeFileDao.search(param));
    }

    @Override
    public UpgradeFileDO select(Long fileId) {
        return upgradeFileDao.getById(fileId);
    }

    @Override
    public UpgradeFileVO selectVO(Long fileId) {
        return UpgradeFileConvert.domainTOVO(upgradeFileDao.getById(fileId));
    }

    @Override
    public boolean checkUniqueName(Long fileId, String fileName) {
        return upgradeFileDao.checkUniqueName(fileId,fileName);
    }

    @Override
    public boolean update(UpgradeFileDO bo) {
        return upgradeFileDao.updateById(bo);
    }

    @Override
    public boolean delete(Long fileId) {
        return upgradeFileDao.removeById(fileId);
    }

    @Override
    public byte[] selectPack(Long fileId) {
        UpgradeFileDO fileDO = upgradeFileDao.getById(fileId);
        return fileDO.getPack();
    }
}